<template>
	<view class="pages">
		<u-navbar title="销售订单详情" :autoBack="true" placeholder bgColor="#fff"></u-navbar>
		<view class="top-tabs"></view>
		<view class="user-info">
			<view class="list">
				<view class="title">订单编号</view>
				<view class="">{{ form.fbillno }}</view>
			</view>
			<view class="list">
				<view class="title">订单状态</view>
				<view class="">
					{{ statusInfo[form.fdocumentstatus] }}
				</view>
			</view>
			<view class="list">
				<view class="title">客户</view>
				<view class="">{{ form.FCustId.FName }}</view>
			</view>
			<view class="list">
				<view class="title">整单金额</view>
				<view class="" style="color: red;">{{ form.fallamount }}</view>
			</view>
			<view class="list">
				<view class="title">下单时间</view>
				<view class="">{{ form.FCreateDate.substring(0, 10) }}</view>
			</view>
			<view class="list">
				<view class="title">业务员</view>
				<view class="">{{ form.FSalerId.FName }}</view>
			</view>
			<view class="list">
				<view class="title">部门</view>
				<view class="">{{ form.FSaleDeptId.FName || '-' }}</view>
			</view>
			<view class="list">
				<view class="title">单据类型</view>
				<view class="">{{ form.FBillTypeID.FName }}</view>
			</view>
			<view class="list">
				<view class="title">是否开发票</view>
				<view class="">{{ form.F_PCYE_Assistant_SFKFP.FDATAVALUE || '-' }}</view>
			</view>
			<view class="list">
				<view class="title">备注</view>
				<view class="">{{ form.FNote || '-' }}</view>
			</view>
		</view>
		<view class="goods-list" v-for="(item, index) in goodsList" :key="index">
			<view class="goods-name">
				{{ index+1 }}.{{ item.fmaterialname }}
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">折扣率：</view>
					<view>{{ item.fdiscount }}</view>
				</view>
				<view class="rowLine">
					<view class="titleName">折扣额：</view>
					<view>{{ item.fdiscountrate }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">存货编码：</view>
					<view>{{ item['FMaterialId.FNumber'] }}</view>
				</view>
				<view class="rowLine">
					<view class="titleName">商品重量：</view>
					<view>{{ item['FMaterialId.FNETWEIGHT'] }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">规格型号：</view>
					<view>{{ item.fmaterialmodel }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">商品属性（零售）：</view>
					<view>{{ item['FMaterialId.F_PCYE_Assistant_apv'] }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">品牌：</view>
					<view>{{ item['FMaterialId.FComBrandId_CMK'] }}</view>
				</view>
				<view class="rowLine">
					<view class="titleName">采购员：</view>
					<view>{{ item['FMaterialId.FPurchaserId'] }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">包装量：</view>
					<view>{{ item['FMaterialId.F_PCYE_Text_83g1'] }}</view>
				</view>
				<view class="rowLine">
					<view class="titleName">销售单位：</view>
					<view>{{ item['funitid.fname'] }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">数量：</view>
					<view>{{ item.fpriceunitqty }}</view>
				</view>
				<view class="rowLine">
					<view class="titleName">单价：</view>
					<view>{{ item.fprice }}</view>
				</view>
				<!-- <view class="rowLine">
					<view class="titleName">赠品：</view>
					<view>{{ item.FIsFree ? '是' : '否' }}</view>
				</view> -->
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">含税单价：</view>
					<view>{{ item.ftaxprice }}</view>
				</view>
				<view class="rowLine">
					<view class="titleName">总价：</view>
					<view>{{ item.FIsFree ? 0 : item.fallamount }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">商品描述：</view>
					<view>{{ item['FMaterialId.FDescription'] }}</view>
				</view>
			</view>
			<view class="infoTabs">
				<view class="rowLine">
					<view class="titleName">备注：</view>
					<view>{{ item.FEntryNote }}</view>
				</view>
			</view>
		</view>
		<view class="bottom-box">
			<!-- <view class="annex">
				<view class="">附件</view>
				<view class="num">2</view>
			</view>
			<view class="box-name">生销货单</view> -->
			<!-- <view class="box-name" @click="copyClick">复制</view> -->
			<view
				class="box-name"
				v-if="form.fdocumentstatus == 'A' || form.fdocumentstatus == 'D'"
				@click="delClick"
			>删除</view>
			<view class="shareBtn" @click="copyClick">复制</view>
			<!-- <view class="shareBtn" @click="downExcel">导出excel</view> -->
			<!-- 暂存、创建、重新审核状态的单据状态允许修改单据 -->
			<view
				class="box-name"
				v-if="form.fdocumentstatus == 'A' || form.fdocumentstatus == 'D' || form.fdocumentstatus == 'Z'"
				@click="editClick"
			>修改</view>
		</view>
	</view>
</template>

<script>
import { getOrderDetail, orderDelete } from '../../api/index'

export default {
	data() {
		return {
			fid: '',
			isFullSucreen: this.isFullSucreen,
			listTabs: [
				{name: '主单据', key: '1'}, {name: '执行情况', key: '2'},
			],
			dataListShow: false,
			form: {},
			goodsList: [],
			statusInfo: {
			  'A': '创建',
			  'B': '审核中（提交）',
			  'C': '已审核',
			  'D': '重新审核',
			  'Z': '暂存',
			},
		}
	},
	onLoad(options) {
		this.fid = options.fid
		if(this.fid) {
			this.getForm()
		}
	},
	methods: {
		downExcel() {
		},
		async delClick() {
			const ress = await uni.showModal({
				title: '提示',
				content: '是否删除该订单？'
			});
			if (ress.confirm) {
				uni.showLoading({ mask: true });
				const parameters =["SAL_SaleOrder",{"Ids":this.fid}]
				orderDelete({parameters}).then(res => {
					if(res.Result.ResponseStatus.IsSuccess) {
						uni.showToast({
							title: '删除成功',
							icon: "success",
						});
						setTimeout(function() {
							uni.navigateBack({
							  delta: 1
							})
						}, 1500)
					} else {
						uni.showToast({
							title: res.Result.ResponseStatus.Errors[0].Message,
							icon: 'none'
						});
					}
				})
			}
		},
		getForm() {
			const parameters = [
        {
          "FormId": "SAL_SaleOrder",
					"FilterString": `fid='${this.fid}'`,
		      "FieldKeys":`fbillno,FEntryNote,FCreateDate,fdocumentstatus,fsaleorgid.fname,fmaterialname,
          fmaterialmodel,funitid.fname,fprice,ftaxprice,fpriceunitid.fname,fpriceunitqty,fdiscountrate,fdiscount,fallamount,
          FMaterialId.FNumber,FMaterialId.FNETWEIGHT,FMaterialId.F_PCYE_Assistant_apv,FMaterialId.FComBrandId_CMK,FMaterialId.FPurchaserId,
          FMaterialId.F_PCYE_Text_83g1,FIsFree,FMaterialId.FDescription,FCustId.FNumber,FCustId.FName,FDate,FSalerId.FNumber,FSalerId.FName,
          FSaleDeptId.FNumber,FSaleDeptId.FName,FBillTypeID.FNumber,FBillTypeID.FName,F_PCYE_Assistant_SFKFP.FNumber,
          F_PCYE_Assistant_SFKFP.FDATAVALUE,FNote`,
          "OrderString": "",
          "TopRowCount": 0,
          "StartRow": 0,
          "Limit": 100,
          "SubSystemId": ""
        }
      ]
			// const parameters = ["SAL_SaleOrder","{'Number':'XSDD202501200045','Id':''}"]
			uni.showLoading({ mask:true })
      getOrderDetail({parameters}).then(res => {
        uni.hideLoading()
        this.form = res[0]
				this.form.fallamount = res.reduce((sum, item) => {
					if(!item.FIsFree) {
						return sum + item.fallamount
					}
					return sum
				}, 0)
        this.goodsList = res
      })
		},
		copyClick() {
			uni.setStorageSync('copyDataList', this.goodsList)
			uni.navigateTo({
			  url: '/other/salesOrder/orderDetail?copyText=fz'
			})
		},
		editClick() {
			uni.setStorageSync('copyDataList', this.goodsList)
			// uni.setStorageSync('copyDataId', this.form.fbillno)
			uni.setStorageSync('copyDataId', this.fid)
			uni.navigateTo({
			  url: '/other/salesOrder/orderDetail?copyText=fz'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
	//文字平均分配
	::v-deep .u-tabs__wrapper__nav[data-v-48634e29] {
		display: flex;
		flex-direction: row;
		position: relative;
		justify-content: space-between;
	}
	//选中蓝色滑块对应
	::v-deep .u-tabs__wrapper__nav__item {
	  flex: 1 1 0% !important;
	}
	.pages{
		width: 750rpx;
		min-height: 100vh;
		background-color: #FAFAFA;
		padding-bottom: 260rpx;
		.top-tabs {
			margin: 10rpx 0 30rpx;
		}
		.user-info {
			width: 100%;
			background-color: #fff;
			padding: 30rpx 40rpx;
			border-radius: 60rpx;
			margin-bottom: 20rpx;
			.list {
				display: flex;
				font-size: 32rpx;
				margin-bottom: 20rpx;
				.title {
					width: 200rpx;
					color: #b7b1b1;
				}
			}
			.foldBtn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 200rpx;
				padding: 10rpx 0;
				border: 1px solid #d7dbd6;
				border-radius: 30rpx;
				margin: 26rpx auto 0;
			}
		}
		.goods-list {
			width: 100%;
			background-color: #fff;
			padding: 30rpx 40rpx;
			border-radius: 60rpx;
			margin-bottom: 20rpx;
			.goods-name {
				font-size: 36rpx;
				font-weight: 600;
				margin-bottom: 20rpx;
			}
			.infoTabs {
				display: flex;
				margin-bottom: 20rpx;
				.rowLine {
					display: flex;
					flex: 1;
					.titleName {
						color: #b7b1b1;
					}
				}
			}
		}
		.bottom-box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			padding: 0 0 70rpx;
			display: flex;
			background-color: #fff;
			text-align: center;
			border-top: 2rpx solid #f0f0f0;
			.annex {
				position: relative;
				flex: 1;
				height: 100rpx;
				line-height: 100rpx;
				.num {
					position: absolute;
					top: 20rpx;
					right: 20rpx;
					width: 40rpx;
					height: 40rpx;
					line-height: 40rpx;
					border-radius: 40rpx;
					text-align: center;
					background-color: red;
					color: #FFF;
				}
			}
			.box-name {
				flex: 1;
				height: 100rpx;
				line-height: 100rpx;
			}
			.shareBtn {
				flex: 1;
				height: 100rpx;
				line-height: 100rpx;
				background-color: #204df0;
				color: #FFF;
			}
		}
	}
</style>